package com.example.examplecarousel;

import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.examplecarousel.adapter.MyAdapter;
import com.example.library.banner.layoutmanager.CenterScrollListener;
import com.example.library.banner.layoutmanager.OverFlyingLayoutManager;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity{

    private RecyclerView mRvMainTest;
    int[] images={R.drawable.yd1,R.drawable.yd2,R.drawable.yd3,R.drawable.yd4,R.drawable.yd5};
    private Handler mHandler;
    private Runnable mRunnable;
    private OverFlyingLayoutManager mOverFlyingLayoutManager;
    private static final String TAG = "c";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        ArrayList<Integer> arrayList=new ArrayList<>();
        for (int i = 0; i < images.length; i++) {
            arrayList.add(images[i]);
        }
        MyAdapter myAdapter=new MyAdapter(MainActivity.this,arrayList);
        mRvMainTest.setAdapter(myAdapter);
        /**
         * 设置轮播图效果的布局管理者
         * 参数介绍：
         * 参数一：0.75表示，划出去的时候item缩放的最小，1表示不缩放的划出去
         * 参数二：100表示有点空隙，300的话就贴在一起了
         * 参数三：方向
         */
        mOverFlyingLayoutManager = new OverFlyingLayoutManager(0.5f, 500, OverFlyingLayoutManager.HORIZONTAL);
        mRvMainTest.setLayoutManager(mOverFlyingLayoutManager);
        mRvMainTest.addOnScrollListener(new CenterScrollListener());//设置滑动后居中item
        //自动轮播
        mHandler = new Handler();
        mRunnable = new Runnable() {
            @Override
            public void run() {
                mCurrentPosition++;
                mOverFlyingLayoutManager.scrollToPosition(mCurrentPosition);
                mHandler.postDelayed(mRunnable,3000);
            }
        };
        mHandler.postDelayed(mRunnable,3000);

    }
    private int mCurrentPosition=0;
    private void initView() {
        mRvMainTest = (RecyclerView) findViewById(R.id.rv_main_test);
    }

}